#include <string.h>

#include <iostream>

using namespace std;

void cus_memcpy(void *dest, const void *src, size_t size) {
  if (dest == NULL || src == NULL) return;
  char *d = (char *)dest;
  char *s = (char *)src;
  for (int i = 0; i < size; ++i) {
    d[i] = s[i];
  }
}

class Base {
 public:
  // 无论是虚还是非虚
  virtual void func(int i) { cout << "Base::func" << endl; }
};

class Dev : public Base {
 public:
  // 不是覆盖
  // 无法通过const分辨函数
  void func(const int i) { cout << "Dev::func" << endl; }
};

// 不构成重载
// void f(int i) { cout << "f(int)" << endl; }
// void f(const int i) { cout << "f(const int)" << endl; }

int main(int argc, char const *argv[]) {
  const char *rs = "ABCDEFG";
  char *ds = new char[10];
  char *ds2 = new char[10];

  memcpy(ds, rs, 7);
  cus_memcpy(ds2, rs, 7);

  cout << "DEST 1: " << ds << endl;
  cout << "DEST 2: " << ds2 << endl;

  delete[] ds;
  delete[] ds2;

  Dev d;
  d.func(5);
  int i = 0;
  d.func(i);
  // 除非限定范围
  d.Base::func(2);

  // 指针实现多态
  Base *bp = new Dev();
  bp->func(1);  // Dev::func
  // 引用实现多态
  Base b2;
  Dev d2;
  Base &rb = b2;
  Base &rd = d2;
  rb.func(2);  // Base::func
  rd.func(3);  // Dev::func

  return 0;
}
